package com.example.service.impl;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.example.pojo.Order;
import com.example.service.OrderService;
import com.example.service.ProductService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.util.Logger;

import java.util.Arrays;

/**
 * @author yinyin
 * @create 2021/09/07 下午 12:11
 */
@Slf4j
@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private ProductService productService;
    @Override
   /* @SentinelResource(value = "selectOrderByIdAndOrderNo",
              blockHandler = "selectOrderByIdAndOrderNoBlockHandler",
              fallback = "selectOrderByIdAndOrderNoFallback"
                  )*/
    public Order selectOrderByIdAndOrderNo(Integer id, String orderNo) {
        return new Order(id,orderNo,"中国",2666D,
                Arrays.asList(productService.selectProductById(1)));
    }

 /*   //服务流量控制处理,参数最后多个BlockException  其余与原函数一致
    public Order selectOrderByIdAndOrderNoBlockHandler(Integer id, String orderNo, BlockException ex){
        ex.printStackTrace();
        return new Order(id,"服务流量控制处理-托底数据","中国",2666D,
                Arrays.asList(productService.selectProductById(1)));
    }

    //服务熔断降级处理
    public Order selectOrderByIdAndOrderNoFallback(Integer id,String orderNo,Throwable throwable){
        log.error("order-service服务的selectOrderById 方法出现异常,异常信息如下:"+throwable);
        return new Order(id,"服务熔断降级处理-托底数据","中国",2777D,
                Arrays.asList(productService.selectProductById(1)));
    }*/

}
